[#ftl]
[#import "common/macrolibs.ftl" as lib]
[#import "common/commondb.ftl" as db]
CREATE TABLE [${db.myTableName}] (
  [id] BigInt IDENTITY(1,1) NOT NULL PRIMARY KEY,
  [name] varchar(128) NOT NULL,
  [description] varchar(256) NULL,
  [disabled] tinyint NULL,[#if clazz.ownerLevel>0]
  [ownerid] BigInt foreign key(ownerid) references ${db.myOwnerTableName}(id),[/#if][#if clazz.scopeClass??]
  [scopeid] BigInt foreign key(scopeid) references ${db.myScopeTableName}(id),[/#if][#list clazz.dynaAttributes as attr][#if !attr.carrier]
  [${db.myFieldNames["${attr.id}"]}] [@lib.dbFieldTypeMsSQL attr=attr/][#if !attr.nullable] NOT NULL[/#if] 
  [#if !attr.carrier&&attr.type>8] foreign key(${db.myFieldNames["${attr.id}"]}) references ${db.myTableAlias}(id) [/#if],[/#if][/#list]
)
[#if clazz.ownerLevel>0]
[/#if]
[#if clazz.scopeClass??]
[/#if]
[#list clazz.dynaAttributes as attr]
EXEC sys.sp_addextendedproperty @name=N'MS_Description', @value=N'${attr.name}' ,@level0type=N'SCHEMA', @level0name=N'dbo', @level1type=N'TABLE', @level1name=N'${db.myTableName}', @level2type=N'COLUMN', @level2name=N'${db.myFieldNames["${attr.id}"]}'
[/#list]